<h1>User</h1>

<form id="sign">
  <input id="alias" placeholder="username">
  <input id="pass" type="password" placeholder="passphrase">
  <input id="in" type="submit" value="sign in">
  <input id="up" type="button" value="sign up">
</form>

<ul></ul>

<form id="said">
    <input id="say">
    <input id="speak" type="submit" value="speak">
</form>

<script src="../jquery.js"></script>
<script src="../../../gun/gun.js"></script>
<script src="../../../gun/sea.js"></script>

<script>
var gun = Gun(); //Gun(['http://localhost:8765/gun', 'https://guntest.herokuapp.com/gun']);
var user = gun.user().recall({sessionStorage: true});

$('#up').on('click', function(e){
	user.create($('#alias').val(), $('#pass').val());
});

$('#sign').on('submit', function(e){
	e.preventDefault();
	user.auth($('#alias').val(), $('#pass').val());
});

gun.on('auth', function(){
	$('#sign').hide();
	user.get('said').map().on(UI);
});

$('#said').on('submit', function(e){
	e.preventDefault();
  if(!user.is){ return }
  user.get('said').set($('#say').val());
  $('#say').val("");
});

function UI(say, id){
  var li = $('#' + id).get(0) || $('<li>').attr('id', id).appendTo('ul');
  $(li).text(say);
};
</script>